<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.kaifamiao.jspcore.Loong" %>

<html>
    <head>
        <title>表达式语言</title>
        <style>
            .wrapper {
                padding: 10px;
                border: 1px solid blue ;
                margin: 10px auto;
            }

            .wrapper>b {
                background: #dfdfdf;
            }
        </style>
    </head>
    <body>

        <h3>表达式语言(Expression Language)</h3>

        <div class="wrapper">
            使用 <b>\${ expression }</b> 或 <b>\#{ expression }</b> 形式在 JSP源文件中书写的字符串就是 EL表达式
        </div>

        <div class="wrapper">
            100 * ( 2 + 5 ) = ${ 100 * ( 2 + 5 ) }
        </div>

        <%
            // 创建Loong实例 (在JSP源代码中可以通过JSP表达式来访问)
            Loong x = new Loong( 1001, "敖润" , '男' );
            // 将Loong实例作为取值设置到请求对象的属性中
            request.setAttribute( "loong", x );
        %>

        <div class="wrapper">
            <h5>用JSP表达式获取对象的属性值</h5>
            <p> id: <%= x.getId() %> </p>
            <p> name: <%= x.getName() %> </p>
            <p> gender: <%= x.getGender() %> </p>
        </div>

        <div class="wrapper">
            <h5>用EL表达式获取对象的属性值</h5>
            <p> id: ${ loong.id } </p>
            <p> name: ${ loong.name } </p>
            <p> gender: ${ loong['gender'] } </p>
        </div>

        <div class="wrapper">
            <h5>通过EL表达式获得JSP内置对象</h5>
            <p>PageContext: ${ pageContext } </p>
            <p>Request: ${ pageContext.request }</p>
            <p>Response: ${ pageContext.response }</p>
            <p>Session: ${ pageContext.session }</p>
            <p>ServletConfig: ${ pageContext.servletConfig }</p>
            <p>ServletContext: ${ pageContext.servletContext }</p>
            <p>Page: ${ pageContext.page }</p>
            <p>JspWriter: ${ pageContext.out }</p>
            <p>Exception: ${ pageContext.exception }</p>
        </div>

    </body>
</html>
